////
////  TextImageView.m
////
////  Created by lijunying on 2/22/2016.
////  Copyright © 2016 Gome. All rights reserved.
////
//
//#import "TextImageView.h"
//@interface TextImageView()
//@property(nonatomic,strong)UITextView *currentText;
//@property(nonatomic,strong)UIView *curentView;
//@property(nonatomic)CGFloat x;
//@property(nonatomic)CGFloat y;
//@end
//@implementation TextImageView 
//-(id)init{
//    if (self = [super init]) {
//        
//    }
//    return self;
//}
//-(id)initWithFrame:(CGRect)frame{
//    self=[super initWithFrame:frame];
//    if (self){
//        self.userInteractionEnabled = true;
//        self.backgroundColor = [UIColor clearColor];
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSelf)];
//        [self addGestureRecognizer:tap];
//    }
//    return self;
//}
//
//-(void)addText{
//    
//    [self tapSelf];
//    
//    UIView * textBg = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 30+20, 35+20)];
//    [self addSubview:textBg];
//    
//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panText:)];
//    [textBg addGestureRecognizer:pan];
//
//    UIButton *exitBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
//    exitBtn.backgroundColor = [UIColor redColor];
//    [exitBtn addTarget:self action:@selector(exitText) forControlEvents:UIControlEventTouchUpInside];
//    exitBtn.tag = 11;
//    [textBg addSubview:exitBtn];
//    
//    UITextView *text = [[UITextView alloc]initWithFrame:CGRectMake(20, 20, 30, 35)];
//    text.layer.borderColor = [UIColor redColor].CGColor;
//    text.layer.borderWidth = 1;
//    text.delegate = self;
//    text.backgroundColor = [UIColor clearColor];
//    text.font = [UIFont systemFontOfSize:16];
//    text.bounces = false;
//    text.scrollEnabled = false;
//    [text becomeFirstResponder];
//    [textBg addSubview:text];
//    
//    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
//    [textBg addGestureRecognizer:pinch];
//    _currentText = text;
//    _curentView = textBg;
//}
//
//-(void)pinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer{
//    UIView *view = pinchGestureRecognizer.view;
//    if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
//        view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
//        pinchGestureRecognizer.scale = 1;
//    }
//}
//
//-(void)exitText{
//    if(_currentText != nil){
//        _currentText.layer.borderColor = [UIColor redColor].CGColor;
//        _currentText.layer.borderWidth = 0;
//        [_currentText resignFirstResponder];
//        [_currentText.superview removeFromSuperview];
//        _currentText = nil;
//    }
//}
//
//-(void)tapSelf{
//    if(_currentText != nil){
//        _currentText.layer.borderColor = [UIColor redColor].CGColor;
//        _currentText.layer.borderWidth = 0;
//        [_curentView viewWithTag:11].hidden = YES;
//        [_currentText resignFirstResponder];
//        if (_currentText.text.length == 0) {
//            [_currentText.superview removeFromSuperview];
//            _currentText = nil;
//        }
//    }
//}
//
//-(void)panText:(UIPanGestureRecognizer *)sender{
//    CGPoint center = [sender translationInView:self];
//    if (sender.state == UIGestureRecognizerStateBegan) {
//        _x = sender.view.center.x;
//        _y = sender.view.center.y;
//    }
//    if (sender.state == UIGestureRecognizerStateEnded){
//        CGFloat textX = sender.view.frame.origin.x;
//        CGFloat textY = sender.view.frame.origin.y;
//        CGFloat textW = sender.view.frame.size.width;
//        CGFloat textH = sender.view.frame.size.height;
//        if (textX < (0-textW+10)||textY<(0-textH+10)){
//            [sender.view removeFromSuperview];
//            _currentText = nil;
//            return;
//        }
//        if (textX > (self.frame.size.width-10) || textY > (self.frame.size.height-10)){
//            [sender.view removeFromSuperview];
//            _currentText = nil;
//            return;
//        }
//        
//    }
//    center = CGPointMake(center.x + _x, center.y + _y);
//    sender.view.center = center;
//}
//
//-(UIImage *)save{
//    [self tapSelf];
//    UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0.0);
//    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
//    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    self.image = img;
//    for (UIView *sub in self.subviews){
//        [sub removeFromSuperview];
//    }
//    return img;
//}
//
//-(void)fillContextFrame{
//    CGSize size = [_currentText sizeThatFits:CGSizeMake(1000, 1000)];
//    if (size.width < 50) {
//        size.width = 50;
//    }
//    CGRect frame = _currentText.frame;
//    frame.size = size;
//    _currentText.frame = frame;
//    CGRect rect =  _currentText.superview.frame;
//    rect.size.width = frame.size.width+20;
//    rect.size.height = frame.size.height+20;
//    _currentText.superview.frame = rect;
//}
//
//-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//    _currentText.layer.borderWidth = 0;
//    [_curentView viewWithTag:11].hidden = YES;
//    textView.layer.borderColor = [UIColor redColor].CGColor;
//    textView.layer.borderWidth = 1;
//    if (self.textSelectColor) {
//        textView.textColor = self.textSelectColor;
//    }else{
//    textView.textColor = [UIColor colorWithRed:( arc4random() % 256 / 256.0 ) green:( arc4random() % 256 / 256.0 ) blue:( arc4random() % 256 / 256.0 ) alpha:1];
//    }
//    _currentText = textView;
//    _curentView = textView.superview;
//    
//    [_curentView viewWithTag:11].hidden = NO;
//    return  true;
//}
//-(void)textViewDidEndEditing:(UITextView *)textView{
//    if (self.textNormalColor){
//        textView.textColor = self.textNormalColor;
//    }else{
//        textView.textColor = [UIColor blackColor];
//    }
//    
//}
//-(void)textViewDidChange:(UITextView *)textView{
//    [self fillContextFrame];
//}
///*
//// Only override drawRect: if you perform custom drawing.
//// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect {
//    // Drawing code
//}
//*/
//
//@end
